package ar.edu.itba.it.pdc.app.admin;


public class AdminRequest {

	public static enum Type {
		LOGIN, LOGOUT, USERRESTRICTION, ERASECONDITION, QUIT, LIST, DELETE, STATISTICS, FILTER, BLACKLIST;
	}
	
	public static enum TUserRestriction {
		INTERVAL, HITS, SERVER;
	}
	
	public static enum TEraseCondition {
		DAYSOLD, SENDERLIST, PATTERNHEADER, MAXSIZE, CONTENTTYPE, STRUCTURE;
	}
	
	public static enum TList {
		USERRESTRICTIONS, ERASECONDITIONS, STATISTICS, FILTERS, BLACKLIST;
	}
	
	public static AdminRequest parse(String text) {
		String []parts = text.split(" ", 2);
		
		AdminRequest ret;
		
		try {
			ret = new AdminRequest(Type.valueOf(parts[0].toUpperCase()));
		}catch(Exception e) {
			return null;
		}
		
		if(parts.length > 1 ) {
			ret.setArguments(parts[1]);
		}
		
		return ret;
	}
	
	private Type type;
	private String arguments;
	
	public AdminRequest(Type type) {
		this.type = type;
	}
	
	public Type getType() {
		return type;
	}

	public void setType(Type type) {
		this.type = type;
	}

	public String getArguments() {
		if(arguments != null) {
			return arguments;
		}
		return "";
	}

	public void setArguments(String arguments) {
		this.arguments = arguments;
	}
	
	public boolean hasArguments() {
		return this.arguments != null && !this.arguments.isEmpty();
	}
	
}
